/**
 * Created by suruixiang on 16/10/18.
 */
$(function(){
    $('#sub').click(function(){
        layer.load();
        $('#form').ajaxSubmit(function(data){
            layer.closeAll('loading');
            if(data.code == 0){
                create_validate_code();
                layer.msg(data.msg, {icon: 5});
            }else{
                layer.msg(data.msg, {icon: 6});
                setTimeout("location.href='/admin/index'", 1000);
            }
        });
    });
    $(':reset').click(function(){
        create_validate_code();
    });
    $('#validate_code').click(function(){
        create_validate_code();
    });
});
function logi()
{
    layer.load();
    $('#form').ajaxSubmit(function(data){
        layer.closeAll('loading');
        if(data.code == 0){
            create_validate_code();
            layer.msg(data.msg, {icon: 5});
        }else{
            layer.msg(data.msg, {icon: 6});
            if (data.url)
                setTimeout("location.href='"+data.url+"'", 1000);
        }
    });
    return false;
}
function create_validate_code(){
    $('#validate_code').attr('src', '/admin/login/validataCode?rz=' + Math.random());
    $('#code').val('');
}
